{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'3'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "str1 = 'mtopjsonp2({\"api\":\"mtop.taobao.couponmtopreadservice.findshopbonusactivitys\",\"v\":\"2.0\",\"ret\":[\"FAIL_SYS_PARAMINVALID_ERROR::检查请求参数非法\"],\"data\":{}})'\n",
    "\n",
    "str1[11:-1]\n",
    "str2 = '390'\n",
    "str2[:-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "[0, 1, 2, 3, 4, 5, 6, 7, 8]\n",
      "8\n",
      "7\n",
      "6\n",
      "5\n",
      "4\n",
      "3\n",
      "2\n",
      "1\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "l = range(9)\n",
    "for i in l:\n",
    "    print i\n",
    "print l\n",
    "l = l[::-1]\n",
    "for i in l:\n",
    "    print i\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://api.m.taobao.com/h5/mtop.taobao.couponmtopreadservice.findshopbonusactivitys/2.0/%3FappKey%3D12574478%26t%3D1494380654882%26sign%3Daf424a69ae3dfbf56ba3cf229237f9d7%26api%3Dmtop.taobao.couponMtopReadService.findShopBonusActivitys%26v%3D2.0%26AntiFlood%3Dtrue%26ecode%3D1%26type%3Djsonp%26dataType%3Djsonp%26callback%3Dmtopjsonp2%26data%3D%7B%22uuid%22%3A%22484d7b9f1ae9475985825ff46644d51e%22%2C%22sellerId%22%3A%22484d7b9f1ae9475985825ff46644d51e%22%2C%22queryShop%22%3Atrue%7D\n"
     ]
    }
   ],
   "source": [
    "import urllib2\n",
    "import re\n",
    "url = 'https://api.m.taobao.com/h5/mtop.taobao.couponmtopreadservice.findshopbonusactivitys/2.0/?appKey=12574478&t=1494380654882&sign=af424a69ae3dfbf56ba3cf229237f9d7&api=mtop.taobao.couponMtopReadService.findShopBonusActivitys&v=2.0&AntiFlood=true&ecode=1&type=jsonp&dataType=jsonp&callback=mtopjsonp2&data={\"uuid\":\"484d7b9f1ae9475985825ff46644d51e\",\"sellerId\":\"484d7b9f1ae9475985825ff46644d51e\",\"queryShop\":true}'\n",
    "\n",
    "url = urllib2.quote(url)\n",
    "url = re.sub(r'https.*?//','https://',url)\n",
    "print url"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "商品优惠券\n"
     ]
    }
   ],
   "source": [
    "data = [{'status': [u'\\u786e\\u8ba4\\u9886\\u53d6'], 'couponStatus': 1, 'shopName': '\\xe7\\x8e\\x9b\\xe7\\xb4\\xa0\\xe5\\x88\\x9b\\xe6\\x84\\x8f\\xe7\\x99\\xbe\\xe8\\xb4\\xa7', 'money': '10', 'useCount': '130', 'startTime': '2017-05-03 00:00:00', 'leaveCount': 1870, 'endTime': '2017-05-10 23:59:59', 'id': 54778, 'condition': '39', 'name': '\\xe5\\x95\\x86\\xe5\\x93\\x81\\xe4\\xbc\\x98\\xe6\\x83\\xa0\\xe5\\x88\\xb8'}]\n",
    "\n",
    "print data[0]['name']\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
